package com.culturalCenter.dataCenter.mapper.user;

import com.culturalCenter.dataCenter.customEntity.user.CustomUserRecent;
import com.culturalCenter.dataCenter.entity.user.UserFootprint;
import com.culturalCenter.dataCenter.entity.user.UserFootrpintCount;
import com.culturalCenter.dataCenter.entity.user.UserInfoCount;
import com.culturalCenter.dataCenter.mapper.base.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserFootprintMapper extends BaseMapper<UserFootprint> {

    /**
     * 通过用户id查询
     *
     * @param userId 用户id
     *
     * @return
     */
    List<UserFootprint> queryByUserId(@Param("userId") String userId);

    /**
     * 查询当前页需要的日期
     *
     * @param userId
     * @param offset
     * @param pageSize
     *
     * @return
     */
    @Select("SELECT DISTINCT DATE_FORMAT(time,'%Y-%m-%d') AS time FROM cdc_user_footprint WHERE userId = #{userId} GROUP BY time ORDER BY time DESC LIMIT #{offset}, #{pageSize}")
    List<String> findDateList(@Param("userId") String userId, @Param("offset") int offset, @Param("pageSize") int pageSize);

    /**
     * 根据用户和日期查询
     *
     * @param userId
     * @param date
     *
     * @return
     */
    @Select("SELECT * FROM cdc_user_footprint WHERE userId = #{userId} AND DATE_FORMAT(time,'%Y-%m-%d') = #{date}")
    List<UserFootprint> findListByUserAndDate(@Param("userId") String userId, @Param("date") String date);

    long finDateCount(@Param("userId") String userId);

    /**
     * 查询最近5条浏览记录
     *
     * @param userId
     *
     * @return
     */
    @Select("SELECT f.activityName, f.activityType, f.time FROM `cdc_user_footprint` f WHERE userId = #{userId} ORDER BY time DESC LIMIT 5")
    List<CustomUserRecent> findCustomUserRecent(@Param("userId") String userId);

    /**
     * 批量插入数据
     *
     * @param userFootprintList
     */
    void insertBatch(List<UserFootprint> userFootprintList);

    /**
     * 根据用户分组查询最近浏览网站时间
     *
     * @return
     */
    List<UserInfoCount> selectRecentFootprint();

    /**
     * 统计用户浏览记录
     *
     * @return
     */
    List<UserFootrpintCount> countUserFootprint();

}
